﻿using ConsoleAppEFCoreTest1.Model;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace ConsoleAppEFCoreTest1
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // LocalContext context = new LocalContext();
            // Book book = new Book() { Author = "龙浩天", Description = "这还是一本好书", Name = "缸体说明", Price = 10.2m, PubTime = DateTime.UtcNow };
            //await context.Books.AddAsync(book);
            // context.SaveChanges();
            // context.Dispose();

            #region 多对多

            //using (LocalContext context = new LocalContext())
            //{


            //    Student s1 = new Student() { Name = "wang" };
            //    Student s2 = new Student() { Name = "wang" };
            //    Student s3 = new Student() { Name = "wang" };

            //    Teacher t1 = new Teacher() { Name = "王一" };
            //    Teacher t2 = new Teacher() { Name = "王2" };
            //    Teacher t3 = new Teacher() { Name = "王3" };

            //    s1.Teachers.Add(t1);
            //    s1.Teachers.Add(t2);

            //    s2.Teachers.Add(t2);
            //    s2.Teachers.Add(t3);

            //    s3.Teachers.Add(t1);
            //    s3.Teachers.Add(t3);

            //    context.Students.Add(s1);
            //    context.Students.Add(s2);
            //    context.Students.Add(s3);

            //    context.Teachers.Add(t1);
            //    context.Teachers.Add(t2);
            //    context.Teachers.Add(t3);

            //    context.SaveChanges();
            //}

            using (LocalContext context = new LocalContext())
            {
                //var s = context.Students.Include(s => s.Teachers).Where(s => s.Id >1).ToList();
                //s.ForEach(s =>
                //{
                //    Console.WriteLine($"{s.Name} has Teachers");
                //    s.Teachers.ForEach(t =>
                //    {
                //        Console.WriteLine("Name:{0} ", arg0: t.Name);
                //    });
                //    Console.WriteLine("--------------");
                //});

                var t = context.Teachers.Include(s => s.Students).Where(s => s.Id > 1);
                //t.ForEach(s =>
                //{
                //    Console.WriteLine($"{s.Name} has Stuendts");
                //    s.Students.ForEach(t =>
                //    {
                //        Console.WriteLine("Name:{0} ", arg0: t.Name);
                //    });
                //    Console.WriteLine("--------------");
                //});

            
            }

            #endregion
        }
    }
}
